<!-- 平台日志 -->
<template>
  <div class="page-main">
    <CustomForm :formInline="form" @onSubmit="onSubmit" @resetTable="resetTable">
      <el-form-item label="反馈类型">
        <el-select v-model="form.type" placeholder="选择反馈类型" @change="initial">
          <el-option label="全部" :value="0"></el-option>
          <el-option label="反馈" :value="1"></el-option>
          <el-option label="举报" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="问题类型">
        <el-select v-model="form.titleType" placeholder="选择问题类型" @change="initial">
          <el-option label="全部" :value="0"></el-option>
          <el-option label="运费问题" :value="1"></el-option>
          <el-option label="账号问题" :value="2"></el-option>
          <el-option label="接单问题" :value="3"></el-option>
          <el-option label="其他问题" :value="4"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="提交时间">
        <el-date-picker
          v-model="pickerData"
          @change="pickerChange"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="回复时间">
        <el-date-picker
          v-model="pickerData2"
          @change="pickerChange2"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
    </CustomForm>
    <el-table
      :data="list"
      style="width: 100%"
      height="700"
      v-loading="tableloading"
      border
      ref="multipleTable"
    >
      <el-table-column prop="user_name" label="反馈人" align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="title_id" label="反馈类型" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span v-if="scope.row.title_id == 1">运费问题</span>
          <span v-if="scope.row.title_id == 2">账号问题</span>
          <span v-if="scope.row.title_id == 3">接单问题</span>
          <span v-if="scope.row.title_id == 4">其他问题</span>
        </template>
      </el-table-column>
      <el-table-column prop="type" label="问题类型" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span v-if="scope.row.type == 1">反馈</span>
          <span v-if="scope.row.type == 2">举报</span>
        </template>
      </el-table-column>
      <el-table-column prop="title" label="标题" align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="desc" label="描述内容" align="center" :show-overflow-tooltip="true"></el-table-column>

      <el-table-column prop="contact_tel" label="联系电话" align="center" :show-overflow-tooltip="true"></el-table-column>

      <el-table-column prop="add_time" label="提交时间" align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="reply_desc" label="回复内容" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ scope.row.reply_desc ? scope.row.reply_desc : '暂无' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="reply_time" label="回复时间" align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column
        prop="admin_user_name"
        label="回复姓名"
        align="center"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.admin_user_name ? scope.row.admin_user_name : '暂无' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <el-button
            v-if="!scope.row.reply_desc"
            type="primary"
            size="mini"
            @click="replay(scope.row)"
          >回复</el-button>
          <el-button type="danger" size="mini" @click="deleteFeed(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="form.page"
      :page-sizes="$pageSizeList"
      :page-size="form.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>
  </div>
</template>
  
  <script>
import { feedbackList, replyBack,deleteFeedBack } from "@/api/set.js";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      form: {
        time:'',
        replyTime:'',
        type:'',//反馈类型 0全部 1反馈 2举报
        titleType:'',//问题类型 0全部 1运费问题 2账号问题 3接单问题 4其他问题
        page: 1,
        pageSize: 10
      },
      list: [],
      total: 0,
      pickerData: [],
      pickerData2: [],
      tableloading: false
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    async initial() {
      this.tableloading = true;
      let res = await feedbackList(this.form);
      this.tableloading = false;
      if (res.code == 200) {
        this.list = res.data.data;
        this.total = res.data.total;
      }
    },
    onSubmit() {
      this.form.page = 1;
      this.form.pageSize = 10;
      this.initial();
    },
    replay(row) {
      //锁定
      this.$prompt("请输入回复内容", "回复", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputPlaceholder: "回复内容",
        inputValidator: val => {
          return val ? true : "回复内容不能为空!";
        }
      })
        .then(async ({ value }) => {
          let res = await replyBack({
            reply_desc: value,
            id: row.id,
            admin_user_name: this.$globalInfo().userName
          });
          if (res.code == 200) {
            this.$message.success("回复成功！");
            this.initial();
          }
        })
        .catch(() => {});
    },
    resetTable() {
      this.pickerData = []
      this.pickerData2 = []
      this.form ={
        time:'',
        replyTime:'',
        type:'',//反馈类型 0全部 1反馈 2举报
        titleType:'',//问题类型 0全部 1运费问题 2账号问题 3接单问题 4其他问题
        page: 1,
        pageSize: 10
      };
      this.initial();
    },
    handleSizeChange(pageSize) {
      this.form.pageSize = pageSize;
      this.initial();
    },
    handleCurrentChange(page) {
      this.form.page = page;
      this.initial();
    },
    pickerChange(val) {
      if (val && val.length > 0) {
        this.form.time = val.join(" - ");
      } else {
        this.form.time = '';
      }
      this.initial();
    },
    pickerChange2(val) {
      if (val && val.length > 0) {
        this.form.replyTime = val.join(" - ");
      } else {
        this.form.replyTime = '';
      }
      this.initial();
    },
    deleteFeed(row){
      this.$confirm("确定删除该反馈吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(async () => {
          let result = await deleteFeedBack({
            id: row.id,
          });
          if (result.code == 200) {
            this.$message({
              type: "success",
              message: "删除成功!"
            });
            this.resetTable();
          }
        })
        .catch(() => {});
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.initial();
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {} //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
  <style lang='scss' scoped>
//@import url(); 引入公共css类
::v-deep .el-pagination {
  margin-top: 20px;
}

::v-deep .el-table .el-table__cell {
  padding: 10px 0;
}
</style>